package com.viking.car;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 消息头
 */
public class MessageHeader {
    private int Package_Header = Constants.PACKAGE_HEADER; //固定值，标识每个消息的开始，0xE1,0x2B,0xD3,0x78
    private int Total_Length;  //消息总长度（包括消息头、消息体和消息尾）
    private int Command_id;
    private int Sequence_id;
    private short Version = Constants.VERSION;
    private int Reserved = 0;//保留字段，暂时为0


    public MessageHeader(){

    }

    public MessageHeader(int total_Length, int command_id, int sequence_id) {
        Total_Length = total_Length;
        Command_id = command_id;
        Sequence_id = sequence_id;
    }

    public int getPackage_Header() {
        return Package_Header;
    }

    public void setPackage_Header(int package_Header) {
        Package_Header = package_Header;
    }

    public int getTotal_Length() {
        return Total_Length;
    }

    public void setTotal_Length(int total_Length) {
        Total_Length = total_Length;
    }

    public int getCommand_id() {
        return Command_id;
    }

    public void setCommand_id(int command_id) {
        Command_id = command_id;
    }

    public int getSequence_id() {
        return Sequence_id;
    }

    public void setSequence_id(int sequence_id) {
        Sequence_id = sequence_id;
    }

    public short getVersion() {
        return Version;
    }

    public void setVersion(short version) {
        Version = version;
    }

    public int getReserved() {
        return Reserved;
    }

    public void setReserved(int reserved) {
        Reserved = reserved;
    }

    @Override
    public String toString() {
        return "{" +
                "Package_Header=" + Package_Header +"(0xE1 0x2B 0xD3 0x78)"+
                ", Total_Length=" + Total_Length +
                ", Command_id=" + Command_id + "("+MAP.get(Command_id)+")"+
                ", Sequence_id=" + Sequence_id +
                ", Version=" + Version +
                ", Reserved=" + Reserved +
                '}';
    }

    private static final Map<Integer,String> MAP = new HashMap<Integer, String>();
    static {
        MAP.put(0x00000001,"0x00000001");
        MAP.put(0x00000002,"0x00000002");
        MAP.put(0x00000003,"0x00000003");
        MAP.put(0x00000004,"0x00000004");
        MAP.put(0x00000005,"0x00000005");
        MAP.put(0x80000001,"0x80000001");
        MAP.put(0x80000002,"0x80000002");
        MAP.put(0x80000003,"0x80000003");
        MAP.put(0x80000004,"0x80000004");
        MAP.put(0x80000005,"0x80000005");
    }
}
